

/*------------------------------------------------------------------------------
	1. Housekeepings
------------------------------------------------------------------------------*/

	*Settings
		set more off
		pause off
		clear
	
	*Set Globals
		global data = "...\Data"
		global output = "...\Output\Tables"
		
		
/*------------------------------------------------------------------------------
	2. Create Table 1:
------------------------------------------------------------------------------*/

import excel using "${data}\table_backup_data.xlsx", clear first sheet("cover_1095_2018")

	set obs 18
	foreach x in  ct census_ct {
		qui summ `x', de
		replace `x' = r(sum) if _n == 18
	}
	
	replace pct_share = (ct/census_ct) if _n == 18
		replace pct_share = pct_share*100
	
	foreach i of varlist ct census_ct pct_share {
		mkmat `i', matrix(`i')
		mat `i' = `i''
	}

	cap program drop claim_dat
	program claim_dat, eclass
		*returned in e() structure
		foreach i of varlist ct census_ct pct_share {
			eret mat `i' = `i'
		}
	end

	estimates clear
	eststo clear

	claim_dat
#delimit ;
esttab using "$output/1095 share by age.tex", replace
	booktabs nogaps label noobs collabels(none) nonumber eqlabels(none) nomtitles 
	cells("ct (fmt(%10.0fc)) census_ct (fmt(%10.0fc)) pct_share (fmt(%10.1fc))") 
	prehead(\begin{table}[htbp]   
			\footnotesize
			\caption{2018 Form 1095 Coverage Rate by Age of Child} 
			\label{tab:1095_by_age}
			\makebox[\textwidth][c]{
			\centering                                      
			\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}                        
			\begin{tabular}{l*{1}{ccc}}   
			\toprule
			&\multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)}   & \multicolumn{1}{c}{(3)} \\                            
			\cmidrule(lr){2-4}
			& \multicolumn{1}{c}{1095 Count} & \multicolumn{1}{c}{Census Count} & \multicolumn{1}{c}{Share (\%)} \\                
			\midrule) 
	varl(r1 "\hspace{0.6cm} 0"
	   	 r2 "\hspace{0.6cm} 1"
	     r3 "\hspace{0.6cm} 2"
		 r4 "\hspace{0.6cm} 3"
		 r5 "\hspace{0.6cm} 4"
		 r6 "\hspace{0.6cm} 5"
		 r7 "\hspace{0.6cm} 6"
	   	 r8 "\hspace{0.6cm} 7"
	     r9 "\hspace{0.6cm} 8"
		 r10 "\hspace{0.6cm} 9"
		 r11 "\hspace{0.6cm} 10"
		 r12 "\hspace{0.6cm} 11"
	   	 r13 "\hspace{0.6cm} 12"
	     r14 "\hspace{0.6cm} 13"
		 r15 "\hspace{0.6cm} 14"
		 r16 "\hspace{0.6cm} 15"
		 r17 "\hspace{0.6cm} 16"
		 r18 "\midrule \hspace{0.6cm} 0-16")
		 postfoot(\midrule 
		 \multicolumn{5}{p{2in}}{\footnotesize{\emph{Notes:"The table reports the estimated fraction of U.S. children by age who appear on a Form 1095 by year. The estimate (reported in Column 3) is derived by dividing the total number of U.S. children of the specified age appearing on a Form 1095 (Column 1) by the total number of children of the specified age estimated by \citet{census_2020} to live in the U.S. (Column 2)."} }}        
			\end{tabular}}
			\end{table});;
			#delimit cr